/**
 * CommonParamFactory.java
 * com.sitech.dmcs.core.factory
 * Function： TODO 
 *
 *   ver  author   date    
 * ──────────────────────────────────
 *   	 geutopia  Jan 20, 2011        
 *
 * Copyright (c) 2011, TNT All Rights Reserved.
*/

package com.sitech.timing.param.impl;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;
import org.directwebremoting.annotations.Param;

import com.sitech.timing.domain.ParamType;
import com.sitech.timing.param.ParamBuilder;
import com.sitech.timing.param.ParamObjectFactoy;



/**
 * ClassName:CommonParamFactory
 * Function: TODO ADD FUNCTION
 * Reason:	 TODO ADD REASON
 *
 * @author   geutopia
 * @version  
 * @since    Ver 1.1
 * @Date	 2011	Jan 20, 2011		1:37:32 PM
 *
 * @see 	 
 */

public class CommonParamFactory implements ParamObjectFactoy,ParamBuilder
{

	/**
	 * (non-Javadoc)
	 * @see com.sitech.dmcs.core.param.ParamObjectFactoy#createParamObject(java.lang.String)
	 */
	public Object createParamObject(String className)
	{
		try
		{
			return Class.forName(className).newInstance();
		}
		catch (InstantiationException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (IllegalAccessException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (ClassNotFoundException e)
		{
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * (non-Javadoc)
	 * @see com.sitech.dmcs.core.param.ParamBuilder#build(java.lang.Object, java.util.Map)
	 */
	public Object build(Object object, Map<String, Object> valueMap,ParamType paramType)
	{
		try
		{
			BeanUtils.populate(object, valueMap);
		}
		catch (IllegalAccessException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (InvocationTargetException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return object;
	}
}
